﻿using System;
using System.Windows;
using YwangHRMSys.DAL;
using YwangHRMSys.Model;


namespace YwangHRMSys.UI.SystemMgr.CategoryMgr
    {
        /// <summary>
        ///     CategoryWindowEdit.xaml 的交互逻辑
        /// </summary>
        public partial class CategoryWindowEdit : Window
            {

                public CategoryWindowEdit()
                {
                    InitializeComponent();
                }

                public string Category { get; set; }

                /// <summary>
                ///     判断是否为添加信息
                /// </summary>
                public bool IsInsert { get; set; }

                /// <summary>
                ///     根据ID来传值
                /// </summary>
                public Guid EditGuid { get; set; }

                private void Window_Loaded( object sender, RoutedEventArgs e )
                {
                    //查询出数据库中有多少的类别
                    CmbCategory.ItemsSource = new CategoryDAL().ListCategory();
                    //  CmbCategory.Text = "性别";
                    if (IsInsert)
                        {

                        }
                            //从数据库中取值，传入文本框
                    else
                        {
                            var dal = new CategoryDAL();
                            CategoryModel model = dal.GetById(EditGuid);
                            TxtName.Text = model.Name;
                         
                        }
                }

                private void BtnSave_Click( object sender, RoutedEventArgs e )
                {

                    string txtName = TxtName.Text;
                    string txtCategory = CmbCategory.Text;
                    var category = new CategoryModel();
                    category.Name = txtName;
                    category.Category = txtCategory;
                    if (IsInsert)
                        {

                            new CategoryDAL().Insert(category);
                            DialogResult = true;
                        }
                    else
                        {
                            category.Id = EditGuid;
                            new CategoryDAL().Update(category);
                            DialogResult = true;
                        }


                }

                private void BtnCancel_Click( object sender, RoutedEventArgs e )
                {
                    DialogResult = false;
                }

            }
    }